package com.ruoyi.project.management.tranfer.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.management.delay.domain.TaskDelay;
import com.ruoyi.project.management.tranfer.domain.TaskTransfer;
import com.ruoyi.project.management.tranfer.service.ManagementTransferService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/management/transfer")
public class ManagementTransferController extends BaseController {

    @Autowired
    private ManagementTransferService managementTransferService;

    private String prefix = "management/transfer";

    /**
     * 跳转到任务转移
     * @return
     */
    @GetMapping()
    public String task()
    {
        return prefix + "/tranf";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TaskTransfer transfer)
    {
        startPage();
        List<TaskTransfer> list = managementTransferService.selectAll(transfer);
        return getDataTable(list);
    }

    /**
     * 新增转移任务
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TaskTransfer taskTransfer)
    {
        taskTransfer.setAuditor("董事长");
        taskTransfer.setPass(0);
        return toAjax(managementTransferService.insert(taskTransfer));
    }



    /**
     * 修改任务转移
     */
    @GetMapping("/edit/{transfer_id}")
    public String edit(@PathVariable("transfer_id") Integer transfer_id, ModelMap mmap)
    {
        mmap.put("tranf", managementTransferService.selectById(transfer_id));
        return prefix + "/edit";
    }

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TaskTransfer taskTransfer)
    {

        return toAjax(managementTransferService.update(taskTransfer));
    }


    /**
     * 根据延期id查看任务信息
     * @param
     * @param mmap
     * @return
     */
    @GetMapping("/detail/{transfer_id}")
    public String show(@PathVariable("transfer_id") Integer transfer_id, ModelMap mmap)
    {
        mmap.put("tranf", managementTransferService.selectById(transfer_id));

        return prefix + "/show";
    }






    // 删除
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        try
        {
            return toAjax(managementTransferService.delete(ids));
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }








}
